home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Precognition / Project.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-13  |  6.2 KB  |  358 lines

  1. #include "project.h"
  2. #include <exec/types.h>
  3. #include "FileRequester/pcg_FileReq.h"
  4. #include "BuilderWindow.h"
  5. #include "BuilderMethods/BuilderMethods.h"
  6. #include "saveprompt.h"
  7. #include "BuilderMethods/panelio.h"
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include "MsgWindow.h"
  11. #include "makeicon.h"
  12. #include "dumpwait.h"
  13.  
  14. extern struct FileReqInfo filereq_info;
  15. extern BuilderWindow builderwindow;
  16.  
  17. void Builder_Init( void );
  18. void Builder_CleanUp( void );
  19. void Builder_Reset( BOOL reopen );
  20. void EnableAllChainedWindows( BOOL );
  21.  
  22. #define STRINGSIZE 129
  23.  
  24. BOOL proj_modified;
  25. BOOL proj_done;
  26.  
  27. char proj_file[STRINGSIZE];
  28. char proj_code[STRINGSIZE];
  29.  
  30. char *proj_filename;
  31. char *proj_codename;
  32.  
  33. char message[80];
  34.  
  35. void Project_Init( void )
  36. {
  37.    proj_modified = FALSE;
  38.    proj_done     = FALSE;
  39.  
  40.    proj_filename = NULL;
  41.    proj_codename = NULL;
  42.  
  43.    proj_file[0] = '\0';
  44.    proj_code[0] = '\0';
  45. }
  46.  
  47.  
  48. BOOL Project_Modified( void )
  49. {
  50.    return proj_modified;
  51. }
  52.  
  53. BOOL Project_Done( void )
  54. {
  55.    return proj_done;
  56. }
  57.  
  58.  
  59. BOOL Prompt_Save( void )
  60. {
  61.    int save_choice;
  62.    BOOL result;
  63.  
  64.    if( ! Project_Modified() ) return TRUE;
  65.  
  66.    save_choice = do_SavePrompt();
  67.  
  68.    switch( save_choice )
  69.    {
  70.       case SP_CANCEL:
  71.          result = FALSE;
  72.          break;
  73.  
  74.       case SP_SAVE:
  75.          result = Project_Save();
  76.          break;
  77.  
  78.       case SP_DONT_SAVE:
  79.          result = TRUE;
  80.          break;
  81.    }
  82.    return result;
  83. }
  84.  
  85. void Project_Modify( void )
  86. {
  87.    proj_modified = TRUE;
  88. }
  89.  
  90.  
  91. void Project_Quit( void )
  92. {
  93.    if( Prompt_Save() )
  94.       proj_done = TRUE;
  95. }
  96.  
  97.  
  98. /*-------------------------------*/
  99.  
  100.  
  101. BOOL Project_WriteIFF( void )
  102. {
  103.    FILE          *file;
  104.  
  105.    if( file = fopen( proj_file, "w" ) )
  106.    {
  107.  
  108.    /*   printf( "Saving \"%s\"...\n", proj_file ); */
  109.  
  110.       WritePrecogForm( file, &builderwindow );
  111.  
  112.       fclose( file );
  113.  
  114.       proj_modified = FALSE;
  115.       proj_filename = proj_file;
  116.  
  117.       makeIcon( proj_file );
  118.  
  119.       return TRUE;
  120.    }
  121.    else
  122.    {
  123.       sprintf( message, "Couldn't open file \"%s\"", proj_file );
  124.       do_MsgWindow( message );
  125.       return FALSE;
  126.    }
  127. }
  128.  
  129. BOOL Project_ReadIFF( void )
  130. {
  131.    FILE          *file;
  132.    long           status;
  133.    BOOL           result;
  134.  
  135.  
  136.    if( ( file = fopen( proj_file, "r" ) ) != NULL )
  137.    {
  138.  
  139.    /*   printf("Reading \"%s\"...\n", proj_file );   */
  140.  
  141.       status = ReadPrecogFile( file, &builderwindow );
  142.  
  143.       fclose( file );
  144.  
  145.       proj_modified = FALSE;
  146.       proj_filename = proj_file;
  147.  
  148.       result = (BOOL)( !status );
  149.  
  150.       if( status < 0 )
  151.       {
  152.          sprintf( message, "Don't understand file \"%s\".", proj_file );
  153.          do_MsgWindow( message );
  154.       }
  155.    }
  156.    else
  157.    {
  158.       sprintf( message, "Couldn't open file \"%s\"", proj_file );
  159.       do_MsgWindow( message );
  160.       result = FALSE;
  161.    }
  162.  
  163.    return result;
  164. }
  165.  
  166.  
  167. BOOL Project_Save_As( void )
  168. {
  169.    BOOL result = FALSE;
  170.  
  171.    EnableAllChainedWindows( FALSE );
  172.  
  173.  
  174.    filereq_info.title        = "Save as what file?";
  175.    filereq_info.MustExist    = FALSE;
  176.    filereq_info.FullPathName = proj_file;
  177.  
  178.    if( proj_file[0] == '\0' ) /* Create a default filename. */
  179.    {
  180.       strcat( proj_file, PObjectName( (struct PObject *)&builderwindow ) );
  181.    }
  182.  
  183.    if( pcg_FileReq( &filereq_info ) )
  184.    {
  185.       result = Project_WriteIFF();
  186.    }
  187.    else
  188.    {
  189.       result = FALSE;
  190.    }
  191.  
  192.    EnableAllChainedWindows( TRUE );
  193.  
  194.    return result;
  195. }
  196.  
  197.  
  198. BOOL Project_Save( void )
  199. {
  200.    BOOL result;
  201.  
  202.    if( proj_filename == NULL )
  203.    {
  204.       result = Project_Save_As();
  205.    }
  206.    else
  207.    {
  208.       EnableAllChainedWindows( FALSE );
  209.       result = Project_WriteIFF();
  210.       EnableAllChainedWindows( TRUE );
  211.    }
  212.  
  213.    return result;
  214. }
  215.  
  216.  
  217.  
  218. BOOL Project_New( void )
  219. {
  220.    if( Project_Modified() )
  221.    {
  222.       /* Prompt for save */
  223.       if( ! Prompt_Save() )
  224.          return FALSE;
  225.    }
  226.  
  227.    Builder_Reset( TRUE );
  228.    Project_Init();
  229.  
  230.    return TRUE;
  231. }
  232.  
  233.  
  234. BOOL Project_Open( void )
  235. {
  236.    BOOL result = FALSE;
  237.  
  238.  
  239.    if( Project_Modified() )
  240.    {
  241.       /* Prompt for save */
  242.       if( ! Prompt_Save() )
  243.          return FALSE;
  244.    }
  245.  
  246.  
  247.    EnableAllChainedWindows( FALSE );
  248.  
  249.    Builder_Reset( FALSE );
  250.    Project_Init();
  251.  
  252.    filereq_info.title        = "Open which file?";
  253.    filereq_info.MustExist    = TRUE;
  254.    filereq_info.FullPathName = proj_file;
  255.  
  256.    if( pcg_FileReq( &filereq_info ) )
  257.    {
  258.       result = Project_ReadIFF();
  259.    }
  260.    else
  261.    {
  262.       result = FALSE;
  263.    }
  264.  
  265.    pcgOpenWindow( &builderwindow.pw );
  266.  
  267.    EnableAllChainedWindows( TRUE );
  268.    return result;
  269. }
  270.  
  271. #include "BuilderMethods/rcsio.h"
  272.  
  273. void
  274. WriteTheCode( FILE *file, BuilderWindow *panel, int section )
  275. {
  276.    GraphicObject *graphic;
  277.    Interactor    *iactor;
  278.  
  279.    WriteCode( (GraphicObject *)panel, panel, file, section );
  280.  
  281.    for( graphic = panel->pw.FirstGraphic; graphic != NULL; graphic = graphic->Next )
  282.    {
  283.       WriteCode( graphic, panel, file, section );
  284.    }
  285.  
  286.    for( iactor = panel->eb.Next; iactor != NULL; iactor = iactor->Next )
  287.    {
  288.       WriteCode( (struct GraphicObject *)iactor, panel, file, section );
  289.    }
  290. }
  291.  
  292. BOOL Project_WriteCode( void )
  293. {
  294.    RCSFILE       *rcsfile;
  295.    FILE          *file;
  296.    short          i;
  297.    BOOL           result = FALSE;
  298.  
  299.    EnableAllChainedWindows( FALSE );
  300.  
  301.  
  302.    filereq_info.title        = "Write code to what file?";
  303.    filereq_info.MustExist    = FALSE;
  304.    filereq_info.FullPathName = proj_code;
  305.  
  306.  
  307.    if( proj_code[0] == '\0' ) /* Create a default filename. */
  308.    {
  309.       strcat( proj_code, PObjectName( (struct PObject *)&builderwindow ) );
  310.       strcat( proj_code, ".c" );
  311.    }
  312.  
  313.    if( pcg_FileReq( &filereq_info ) )
  314.    {
  315.  
  316.       if( rcsfile = rcs_create( proj_code ) )
  317.       {
  318.          file = rcsfile->file;
  319.  
  320.      /*    printf( "Coding \"%s\"\n", proj_code );   */
  321.  
  322.          for( i = 0; i < 1000; i++ )
  323.          {
  324.             WriteTheCode( file, &builderwindow, i );
  325.          }
  326.          rcs_close( rcsfile );
  327.  
  328.          result = TRUE;
  329.       }
  330.       else
  331.       {
  332.          printf( "Couldn't open file \"%s\"\n", proj_code );
  333.          result = FALSE;
  334.       }
  335.    }
  336.    else
  337.    {
  338.       result = FALSE;
  339.    }
  340.  
  341.    EnableAllChainedWindows( TRUE );
  342.  
  343.    return result;
  344. }
  345.  
  346. #include "AboutWindow/do_About_window.h"
  347.  
  348. extern struct MsgPort *shared_port;
  349. extern struct Screen  *screen;
  350.  
  351. void Project_About( void )
  352. {
  353.     EnableAllChainedWindows( FALSE );
  354.     do_About_window( screen, shared_port );
  355.     EnableAllChainedWindows( TRUE );
  356. }
  357.  
  358.